package com.mf.morefun.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mf.morefun.R;
import com.mf.morefun.bean.ListenBean;
import com.zhcx.zhcxlibrary.utils.StringUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ListenAdapter extends BaseAdapter {
    private Context mContext;
    private List<ListenBean> listenBeanList;
    private String selectPosition = "";

    public String getSelectPosition() {
        return selectPosition;
    }

    public void setSelectPosition(String selectPosition) {
        this.selectPosition = selectPosition;
    }

    public ListenAdapter(Context mContext, List<ListenBean> listenBeanList) {
        this.mContext = mContext;
        this.listenBeanList = listenBeanList;
    }

    @Override
    public int getCount() {
        return listenBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return listenBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (null == convertView) {
            view = LayoutInflater.from(mContext).inflate(R.layout.layout_listenitem, null);
        } else {
            view = convertView;
        }
        if (null != listenBeanList && listenBeanList.size() > 0){
            ViewHolder holder = new ViewHolder(view);
            holder.tvBendi.setText(listenBeanList.get(position).getName());
            holder.tvBendi.setTextColor(mContext.getResources().getColor(R.color.main_default_color));
            try {
                if (!StringUtils.isEmpty(getSelectPosition())){
                    if (Integer.parseInt(getSelectPosition()) == position){
                        holder.tvBendi.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.tv_bendi)
        TextView tvBendi;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
